<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
<!--    <div th:replace="~{commons/script::_css}"></div>-->
    <dvi th:replace="~{commons/script::script}"></dvi>
</head>
<body>

<!--    <div th:replace="~{commons/script::_header}"></div>-->
<!--    <div th:replace="~{commons/script::_start}"></div>-->
    <div>
        <span>视图：</span><span onclick="return whole()" class="easyui-linkbutton" data-options="iconCls:'icon-ok',plain:true">全部</span>|
        <span onclick="return myCustomer()" class="easyui-linkbutton" data-options="plain:true">我负责的</span>|
        <span onclick="return subCustomer()" class="easyui-linkbutton" data-options="plain:true">下属负责的</span>|
        <span onclick="return transformed()" class="easyui-linkbutton" data-options="plain:true">已转化的线索</span>
        &nbsp;&nbsp;
        <span onclick="return todayCreate()" class="easyui-linkbutton" data-options="iconCls:'icon-ok',plain:true">今日新建</span>|
        <span onclick="return weekCreate()" class="easyui-linkbutton" data-options="plain:true">本周新建</span>|
        <span onclick="return monthCreate()" class="easyui-linkbutton" data-options="plain:true">本月新建</span>|
        <span onclick="return todayStep()" class="easyui-linkbutton" data-options="plain:true">今日需联系</span>|
        <span onclick="return weekStep()" class="easyui-linkbutton" data-options="plain:true">本周需联系</span>|
        <span onclick="return sevenStep()" class="easyui-linkbutton" data-options="plain:true">7日未联系</span>|
        <span onclick="return fifteenStep()" class="easyui-linkbutton" data-options="plain:true">15日未联系</span>|
        <span onclick="return rencently()" class="easyui-linkbutton" data-options="plain:true">最近修改</span>|
        <span id="recycleBin" class="easyui-linkbutton" data-options="iconCls:'icon-recover_deleted',plain:true">回收站</span>
        &nbsp;
    </div>

    <div id="tools" style="margin-bottom: 20px">
        <form action="/leads/searchLeads">
            <table>
                <tr>
                    <td>
                        <i class="iconfont"></i>
                        <select name="batchOperate" style="width:100px;height:25px;" id="batchOperate">
                            <option value="-1">--批量操作--</option>
                            <option value="0">
                                批量删除
<!--                                <a href="javascript:void(0);" onclick="return del('/leads/deleteLeads')" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true">批量删除</a>-->
                            </option>
                            <option value="1">批量放入线索池</option>
                        </select>
                    </td>
                    <td>
                        <select name="filterSearch" style="width:100px;height:25px;" id="searchBy">
                            <option value="-1">--请选择筛选条件--</option>
                            <option value="0">公司名</option>
                            <option value="1">联系人姓名</option>
                        </select>
                        <select name="contain" style="width:60px;height:25px;">
                            <option value="-1">--包含--</option>
                        </select>
                    </td>
                    <td  class="text-content">
                        <input name="search" type="text" placeholder="请输入查询关键字" id="searchText">
                        <input type="submit" id="search" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true">搜索</input>
                    </td>
                    <td>
                        <span id="chat" class="easyui-linkbutton" data-options="iconCls:'icon-cut',plain:true">发送短信</span>
                        <span id="email" class="easyui-linkbutton" data-options="iconCls:'icon-redo',plain:true">发送邮件</span>
                    </td>

                    <td>
                        <!-- manage/customer/CustomerAction_showAdd.action-->
                        <span onclick="return add('/leads/toAddLeads')" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">新建客户</span>
                        <span id="tool" class="easyui-linkbutton" data-options="iconCls:'icon-cog',plain:true">客户工具</span>
                    </td>
                </tr>
            </table>
        </form>

    </div>
    <div id="customerLs"></div>
</body>

<script type="text/javascript">
    $("#search").on("click",function(event){
        event.preventDefault();
        var searchBy=$("#searchBy").val();
        var searchText=$("#searchText").val();
        $("#customerLs").datagrid("load",{
            "searchBy":$("#searchBy").val(),
            "searchText":$("#searchText").val()
        })
    })

    $(function(){
        //分页展示客户列表
        $("#customerLs").datagrid({
            url:"/leads/listLeads",
            checkOnSelect:false,
            idField:"customerId",
            pagination:true,
            sortName:"customerId",
            columns:[
                        [
                {field:"选择",checkbox:true},
                {field:"id",hidden:true},
                // {field:"follow",title:"关注",
                //     formatter:function(value,row,index){
                //         var isfollowed = false;
                //
                //         $.ajax({
                //             type: "post",
                //             url: "manage/customer/CustomerAction_isfollowed.action",
                //             data:{"customerId":row.id},
                //             dataType: "json",
                //             async : false,
                //             success:function(data){
                //                 if(data&&data.success){
                //                     isfollowed=true;
                //                     return;
                //                 }
                //             }
                //         });
                //
                //
                //         if(!isfollowed){
                //             return "<img onclick='javascript:follow(" +'"' + row.id +'"' +","+index+")' src='static/easyui/themes/icons/stark.png'/>";
                //         }else{
                //             return "<img onclick='javascript:unfollow(" +'"' + row.id +'"' +","+index+")' src='static/easyui/themes/icons/star.png'/>";
                //         }
                //     }},
                {field:"name",title:"公司名"},
                {field:"contactsName",title:"联系人姓名"},
                {field:"saltname",title:"尊称"},
                {field:"mobile",title:"手机"},
                {field:"nextstep",title:"下次联系内容"},
                {field:"nextstepTime",title:"下次联系事件"},
                {field:"ownerName",title:"负责人"},
                {field:"createName",title:"创建人"},
                {field:"createTime",title:"创建时间"},
                {field:"diffDay",title:"据到期天数"},

                // {field:"address",title:"客户联系地址",formatter:function(value){
                //         return "<span title='"+value+"'>"+value+"</span>"
                //     }},
                // {field:"owner",title:"负责人"},
                // {field:"createUser",title:"创建人"},
                // {field:"createTime",title:"创建时间",width:50,formatter:function(value){
                //         return "<span title='"+value+"'>"+value+"</span>"
                //     }},
                // {field:"updateTime",title:"更新时间",width:100,formatter:function(value){
                //         if(value){
                //             return "<span title='"+value+"'>"+value+"</span>";
                //         }
                //         return "";
                //     }},
                // {field:"days",title:"距离到期天数"},
                {field:"operation",title:"操作", width:100,formatter:function(value,rowData,index){
                        return "<a href='javascript:void(0);' onclick=\"return see(\'/leads/showLeads\',\'"+rowData.id+"\')\">查看</a>"+
                            "<a href='javascript:void(0);' onclick=\"return toAddCustomer(\'/customer/cus\',\'"+rowData.id+"\')\">转换</a>"+
                            " <a href='javascript:void(0);' onclick=\"return modify(\'/leads/toUpdateLeads\',\'"+rowData.id+"\')\">编辑</a>"
                    }}

            ]
                ],
            loadFilter:function(data){
                return {total : data.data.totalRows,rows:data.data.result}
            }

        })

    })
    //删除按钮事件处理函数
    function del(url){
        //获取到选中的一行数据
        var rows = $("#customerLs").datagrid("getChecked");
        if(!rows.length){
            $.messager.alert("警告","请选择要删除的数据");
            return;
        }
        $.messager.confirm("警告","数据删除后无法恢复，是否确认删除",function(b){
            if(b){
                var ids = new Array();
                $.each(rows,function(index,obj){
                    ids.push(obj.id);
                });
                //将数组中元素使用,分割拼接为一个字符串
                ids = ids.join(",");
                $.post(url,
                    {
                        "ids" : ids
                    },
                    function(data){
                        if(data && data.success){
                            $.messager.alert("提示",data.message);
                            $("#customerLs").datagrid("reload");
                            return;
                        }
                        $.messager.alert("警告",data.message);
                    },"json");
            }
        });
    }
    //批量放入线索池
    function leadsChi(url){
        //获取到选中的一行数据
        var rows = $("#customerLs").datagrid("getChecked");
        if(!rows.length){
            $.messager.alert("警告","请选择要放入线索池的数据");
            return;
        }
        $.messager.confirm("警告","是否确认放入线索池",function(b){
            if(b){
                var ids = new Array();
                $.each(rows,function(index,obj){
                    ids.push(obj.id);
                });
                //将数组中元素使用,分割拼接为一个字符串
                ids = ids.join(",");
                $.post(url,
                    {
                        "ids" : ids
                    },
                    function(data){
                        if(data && data.success){
                            $.messager.alert("提示",data.message);
                            $("#customerLs").datagrid("reload");
                            return;
                        }
                        $.messager.alert("警告",data.message);
                    },"json");
            }
        });
    }
    //关注客户事件
    function follow(id,index){
        $.post("manage/customer/CustomerAction_follow.action",{
            "customerId":id
        },function(data){
            if(data&&data.success){
                $("#customerLs").datagrid("reload",{
                    "index":index,
                    "row":{
                        "follow":"<img src='static/easyui/themes/icons/star.png'/>"
                    }
                })
            }
        },"json")

    }
    //取消关注客户
    function unfollow(id,index){
        $.post("manage/customer/CustomerAction_unfollow.action",{
            "customerId":id,
        },function(data){
            if(data&&data.success){
                $("#customerLs").datagrid("reload",{
                    "index":index,
                    "row":{
                        "follow":"<img src='static/easyui/themes/icons/stark.png'/>"
                    }
                })
            }
        },"json")
    }
    //查询全部客户
    function whole(url){
        $("#customerLs").datagrid("load",{})
    }
    //查询我负责的
    function myCustomer(){
        $("#customerLs").datagrid("load",{
            "fuzeren":"me"
        })
        // $("#customerLs").datagrid({
        //     "url":url
        // })
    }
    //查询下属负责的
    function subCustomer(){
        $("#customerLs").datagrid("load",{
            "fuzeren":"xiashu"
        })
    }
    //线索转换
    function transformed(){
        $("#customerLs").datagrid("load",{
            "transformed":true
        })
    }
    //查询今天创建的客户
    function todayCreate(){
        $("#customerLs").datagrid("load",{
            "type":"day"
        })
    }
    //查询周创建的客户
    function monthCreate(){
        $("#customerLs").datagrid("load",{
            "type":"month"
        })
    }
    //查询月创建的客户
    function weekCreate(){
        $("#customerLs").datagrid("load",{
            "type":"week"
        })
    }
    //今日需联系
    function todayStep(){
        $("#customerLs").datagrid("load",{
            "step":"today"
        })
    }
    //本周续联系
    function weekStep(){
        $("#customerLs").datagrid("load",{
            "step":"week"
        })
    }
    //7天未联系
    function sevenStep(){
        $("#customerLs").datagrid("load",{
            "step":"seven"
        })
    }
    //15天未联系
    function fifteenStep(){
        $("#customerLs").datagrid("load",{
            "step":"fifteen"
        })
    }
    //最近修改
    function rencently(){
        $("#customerLs").datagrid("load",{
            "step":"update"
        })
    }
    //查询当前用户关注的客户
    function followed(url){
        $("#customerLs").datagrid({
            "url":url
        })
    }

    //页面添加客户
    function add(url){
        parent.parent.openTopWindow({
            "url":url,
            "width":800,
            "height":700,
            "title":"新建客户",
            close:function(){
                $("#customerLs").datagrid("reload");
            }
        })
        // location.href=url;
    }
    //修改客户
    function modify(url,id){
        parent.parent.openTopWindow({
            "url":url+"?id="+id,
            "width":800,
            "height":700,
            "title":"新建客户",
            close:function(){
                $("#customerLs").datagrid("reload");
            }
        })
    }
    //转换成客户
    function toAddCustomer(url,id){
        parent.parent.openTopWindow({
            "url":url+"?leadsId="+id,
            "width":800,
            "height":700,
            "title":"客户信息",
            close:function(){
                $("#customerLs").datagrid("reload");
            }
        })
    }
    //查看客户
    function see(url,id){
        parent.parent.openTopWindow({
            "url":url+"?id="+id,
            "width":800,
            "height":700,
            "title":"客户信息",
            close:function(){
                $("#customerLs").datagrid("reload");
            }
        })
        // window.location.href=url+"?id="+id
    }
</script>
<script type="text/javascript">
    $(function(){
        //邮件发送
        $("#email").on("click", function (e) {
            var rows = $("#customerLs").datagrid("getSelections");
            if (!rows || rows.length == 0) {
                $.messager.alert("警告", "请选中要发送邮件的客户");
                return;
            }
            if(rows.length>1){
                $.messager.alert("警告","请选择单条数据进行发送邮件");
                return false;
            }
            var userId = rows[0].id;

            location.href = "/leads/toSendEmail?id=" + userId;
        })
        //邮件发送
        $("#chat").on("click", function (e) {
            // var rows = $("#customerLs").datagrid("getSelections");
            // alert("111")
            // if (!rows || rows.length == 0) {
            //     $.messager.alert("警告", "请选中要发送短信的客户");
            //     return;
            // }
            // if(rows.length>1){
            //     $.messager.alert("警告","请选择单条数据进行发送短信");
            //     return false;
            // }
            // var userId = rows[0].id;

            location.href = "/leads/toSendMsg"
        })
        $("#batchOperate").bind("change",function (){
            var value = $(this).val();
            if(value==0){
                del('/leads/deleteLeads')
            }else if(value==1){
                leadsChi('/leads/putLeadsChi')
            }

        })
    })

</script>
</html>
